<page-header [title]="l('Roles')"></page-header>

<!-- 表格部分 -->
<nz-card [nzBordered]="false">
  <!-- 检索的表单内容 -->
  <form nz-form [nzLayout]="'vertical'" (ngSubmit)="refreshGoFirstPage()" class="mb-md">
    <!-- 模糊搜索框 -->
    <nz-row nzGutter="8">
      <nz-col nzSm="12">
        <nz-form-item>
          <nz-form-control>
            <nz-input-group nzSearch [nzSuffix]="suffixSearchButton">
              <input type="text" nz-input [(ngModel)]="filterText" (keyup.enter)="refresh()" name="filterText"
                [placeholder]="l('SearchWithThreeDot')">
              <ng-template #suffixSearchButton>
                <button nz-button nzType="primary" nzSearch type="submit">
                  <i class="anticon anticon-search"></i>
                </button>
              </ng-template>
            </nz-input-group>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzSm="12">
        <app-permission-combox [multiple]="true" [dropDownStyle]="{'max-height':'500px'}" [(selectedPermission)]="selectedPermission"
          (selectedPermissionChange)="refreshGoFirstPage()"> </app-permission-combox>
      </nz-col>
    </nz-row>
  </form>






  <div class="mb-md">

    <!-- 操作按钮 -->
    <nz-row nzGutter="8">
      <!-- 添加、批量删除、导出Excel表等按钮 -->
      <nz-col nzMd="20" nzSm="12" class="btn-gutter">

        <button nz-button [nzType]="'primary'" *ngIf="isGranted('Pages.Administration.Roles.Create')" (click)="createOrEdit()">
          <i class="anticon anticon-plus"></i>
          <span>
            {{l("CreateNewRole")}}
          </span>
        </button>
        <button nz-button [nzType]="'danger'" *ngIf="isGranted('Pages.Administration.Roles.Delete')" (click)="batchDelete()">
          <i class="anticon anticon-delete"></i>
          <span>
            {{l("BatchDelete")}}
          </span>
        </button>
      </nz-col>
    </nz-row>


  </div>


  <!-- 数据部分 -->
  <div class="my-md">
    <nz-alert [nzType]="'info'" [nzShowIcon]="true" [nzMessage]="message">
      <ng-template #message>
        <span [innerHTML]="l('GridSelectedXItemsTips',selectedDataItems.length)"></span>
        <a (click)="restCheckStatus(dataList)" class="ml-md">
          {{l('ClearEmpty')}}
        </a>
        <nz-divider nzType="vertical"></nz-divider>
        <a (click)="forceRefresh()">
          {{l('Refresh')}}
        </a>
      </ng-template>
    </nz-alert>
  </div>
  <!-- 表格 -->
  <div class="mb-md">

    <nz-table #ajaxTable nzShowSizeChanger [nzData]="dataList" [nzTotal]="totalItems" [(nzPageIndex)]="pageNumber"
      [(nzPageSize)]="pageSize" [nzLoading]="isTableLoading" (nzPageIndexChange)="pageNumberChange()"
      (nzPageSizeChange)="refresh()" [nzFrontPagination]="false" [nzNoResult]="noDataTemplate" [nzShowTotal]="showTotalTemplate">
      <!-- 暂无数据 -->
      <ng-template #noDataTemplate>
        <no-data></no-data>
      </ng-template>
      <!-- 分页信息显示 当前 1 页/共 3 页，共 5 条/显示 1-2 条 -->
      <ng-template #showTotalTemplate let-total let-range="range">
        {{l('GridFooterDisplayText',pageNumber,totalPages,total,range[0],range[1])}}
      </ng-template>
      <!-- 表头 -->
      <thead>
        <tr>
          <th nzShowCheckbox [(nzChecked)]="allChecked" [nzDisabled]="allCheckboxDisabled" [nzIndeterminate]="checkboxIndeterminate"
            (nzCheckedChange)="checkAll($event)">
          </th>

          <th>
            <span>{{l('RoleName')}}</span>
          </th>
          <th class="text-center">
            <span>{{l('CreationTime')}}</span>
          </th>

          <th nzWidth="230px" class="text-center">
            <span>{{l('Actions')}}</span>
          </th>
        </tr>
      </thead>
      <!-- 表格内容 -->

      <tbody>
        <tr *ngFor="let item of ajaxTable.data">
          <td nzShowCheckbox [(nzChecked)]="item.checked&&!item.isStatic" [nzDisabled]="item.isStatic"
            (nzCheckedChange)="refreshCheckStatus(dataList)"></td>

          <td>
            <ellipsis lines="1">

              <span nz-tooltip [nzTitle]="item.displayName"> {{item.displayName}}</span>

              <nz-tag *ngIf="item.isStatic" [nzColor]="'#108ee9'" nz-tooltip [nzTitle]="l('StaticRole_Tooltip')">{{l('Static')}}</nz-tag>
              <nz-tag *ngIf="item.isDefault" [nzColor]="'#2db7f5'" nz-tooltip [nzTitle]="l('DefaultRole_Description')">{{l('Default')}}</nz-tag>
            </ellipsis>
          </td>
          <td class="text-center">
            <span nz-tooltip [nzTitle]="item.creationTime"> {{item.creationTime|_date}}</span>


          </td>
          <td class="text-center">
            <!-- 编辑 -->
            <ng-container *ngIf="isGranted('Pages.Administration.Roles.Edit')">
              <a (click)="createOrEdit(item.id)">
                <i class="anticon anticon-edit mr-sm"></i>
                <span>{{l('Edit')}}</span>
              </a>
              <nz-divider nzType="vertical"></nz-divider>
            </ng-container>
            <!-- 删除 -->
            <ng-container *ngIf="!item.isStatic&&isGranted('Pages.Administration.Roles.Delete')">
              <nz-popconfirm [nzTitle]="l('ConfirmDeleteWarningMessage')" (nzOnConfirm)="delete(item)" [nzOkText]="l('Ok')"
                [nzCancelText]="l('Cancel')">
                <a nz-popconfirm>
                  <i class="anticon anticon-delete mr-sm"></i>
                  <span>{{l('Delete')}}</span>
                </a>
              </nz-popconfirm>
            </ng-container>
          </td>
        </tr>
      </tbody>
    </nz-table>
  </div>

</nz-card>
